package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsRegion;
import com.qf.service.DtsRegionService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin("*")
@RequestMapping("/region")
public class RegionController {

    @Autowired
    private DtsRegionService regionService;

    //http://localhost:8083/admin/region/list?page=1&limit=20
    @GetMapping("/list")
    public Object list(Integer id,String name,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit) {
        IPage<DtsRegion> dtsRegionIPage = regionService.queryByPage(
                id, name, page, limit);
        long total = dtsRegionIPage.getTotal();
        List<DtsRegion> records = dtsRegionIPage.getRecords();


        Map<String, Object> map = new HashMap<>();
        map.put("total",total);
        map.put("items",records);
        return ResponseUtil.ok(map);
    }
}
